#ifndef SERVERSOCKET_H
#define SERVERSOCKET_H

#include "Socket.h"
#include "SocketMessage.h"
#include "ClientSocket.h"
#include "GameMessage.h"
#include "Vec3.h"
#include "MutexLocker.h"
#include "Mutex.h"

#include <vector>
#include <map>

class ServerSocket : public Socket
{
public:
	ServerSocket();
	~ServerSocket();
	bool Open(int port);
	Socket* Accept();
	bool ReceiveS(SocketMessage* sm);
	bool SendGameMessageToAll(GameMessage& gm);

	void AddClient(ClientSocket* c);
	void CheckMaxPing();
	void SetClientPosition(int id, const Vec3fNet& pos);
	void UpdateClientPositions();
	ClientSocket& GetClient(int id) const;

	void SyncTimers();
	void SyncPositions(int id, const Vec3fNet& pos);
private:
	std::map<int ,ClientSocket*> m_clients;
	Mutex m_mutex;
};

#endif //SERVERSOCKET_H